home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 August: Tool Chest / Dev.CD Aug 95 TC / Dev.CD Aug 95 TC.toast / Sample Code / Snippets / Devices / EgretWakeup / EgretWakeUp.p < prev    next >
Encoding:
Text File  |  1993-11-09  |  7.2 KB  |  241 lines  |  [TEXT/MPS ]

  1. PROGRAM EgretWakeUp;
  2. {
  3.  
  4. 11/02/93 DTS
  5.  
  6. This is a test program to tell a Mac with an Egret (or Egret derivative) 
  7. chip when to power up.  It does so by calling the _Egret trap.
  8.  
  9. If the Power Manager exists, use the SetWUTime call as per Inside
  10. Macintosh, Power  Manager chapter (Vol VI).
  11.  
  12. This program only works on a Egret-based Macs that ALSO can do soft
  13. power.  For example while the IIsi and LC CPUs both have Egrets, LCs
  14. can't do soft power on).
  15.  
  16. I first tried just checking for the Egret trap before making the call, 
  17. but for some reason _Egret exists on Macs that don't have Egrets 
  18. (z.B. QUadra 700,800, Centris 650, Duos).  
  19.  
  20. Calling _Egret on these Macs is FATAL. 
  21.  
  22. Then I found there is a low memory global that has essentially an Egret
  23. family version number.  So this program checks that global.  DTS
  24. will entertain *** no **** questions about this global.  Anyone using
  25. it for any reason other than checking for an Egret does so at EXTREME
  26. risk of breaking.  And in fact even this could break, if the flags
  27. change for some reason.  The flags aren't documented to developers so
  28. this is fair game.  Use this snippet at your own risk!
  29.  
  30. If the CPU isn't capable of soft power then the call to Egret isn't made.
  31.  
  32.  
  33. INSTRUCTIONS:
  34. Set the kMinutesToDelay constant in the CONST section to some number of
  35. minutes (I set it to 1).  Build and then run this program.  If the program
  36. says it can wake up, immediately shut down the Macintosh, and it will power 
  37. up "kMinutesToDelay" minutes after the program is run (not shut down).
  38.  
  39. If the Mac can't wake up due to lack of Egret or soft power capability,
  40. it will say so and not call the Egret trap.
  41.  
  42. useful commands:
  43. pasmat EgretWakeUp.p -r -u > EgretWakeUp.pasmat
  44. print "Internal:MPW:EgretWakeUp.p" -b2 -h -md -font Courier -size 7
  45. print "Internal:MPW:EgretWakeUp.a" -b2 -h -md -font Courier -size 7
  46. print "Internal:MPW:myEgretEqu.a" -b2 -h -md -font Courier -size 7
  47. print "Internal:MPW:EgretWakeUp.make" -b2 -h -md -font Courier -size 7
  48. }
  49.  
  50.  
  51.     USES Memtypes, QuickDraw, OsIntf, ToolIntf, PackIntf, PasLibIntf, GestaltEqu;
  52.  
  53.     CONST
  54.         kProgramVersion = '1.2';
  55.         kMinutesToDelay = 1;
  56.  
  57.     VAR
  58.         gErr: OSErr;
  59.         gPresentTime,
  60.         gWakeUpTime: LONGINT;
  61.  
  62.  
  63.     {-----------------------------------------------------
  64.       HasEgretHW - check for presence of egret/caboose/cuda
  65.       clock chips
  66.      -----------------------------------------------------}
  67.  
  68.     FUNCTION HasEgretHW: BOOLEAN;
  69.  
  70.         CONST
  71.             kMyUnivROMFlags =     $00000DD4;    { USE AT OWN RISK. UNSUPPORTED BY DTS }
  72.             kEgretClockMask    =    $00000070;    { bits 4,5,6 determine what kind of clock machine has. }
  73.                                             { if 010 then machine has an Egret style clock chip. }
  74.             kEgretStyle =        $00000020;    { Egret style machines will equal this after ANDing }
  75.                                             { (UnivRomFlags & kEgretClockMask) }
  76.         VAR
  77.             gotIt : BOOLEAN;
  78.             ROMFlags : LONGINT;
  79.             ROMFlagPtr : LongIntPtr;
  80.  
  81.         BEGIN
  82.             gotIt := FALSE;
  83.             
  84.             { Is Egret hardware available? }
  85.             ROMFlagPtr := Pointer(kMyUnivROMFlags);
  86.             ROMFlags := ROMFlagPtr^;
  87.             
  88.             gotIt := (BAND(ROMFlags,kEgretClockMask) = kEgretStyle);
  89.                                     
  90.             If gotIt THEN
  91.                 Writeln('Checking for presence of Egret hardware.   Result: has Egret hardware.')
  92.             ELSE
  93.                 Writeln('Checking for presence of Egret hardware.   Result:  no Egret hardware.');
  94.             PLFlush(Output);
  95.  
  96.             HasEgretHW := gotIt;
  97.         END;
  98.  
  99.     {-----------------------------------------------------
  100.       HasEgretTrap - check for presence of egret trap.
  101.      -----------------------------------------------------}
  102.  
  103.     FUNCTION HasEgretTrap: BOOLEAN;
  104.  
  105.         CONST
  106.             kEgretTrapNum = $92; { Trap Number of EgretTrapNum }
  107.             kUnImplTrapNum = $9F; { Trap Number of Unimplemented Trap }
  108.  
  109.         BEGIN
  110.             HasEgretTrap := FALSE;
  111.  
  112.             { Is Egret trap available? }
  113.             HasEgretTrap := NGetTrapAddress(kEgretTrapNum, OSTrap) <>
  114.                             NGetTrapAddress(kUnImplTrapNum,ToolTrap);
  115.         END;
  116.         
  117.  
  118.     {-----------------------------------------------------
  119.       HasSoftPower - check for soft power off capability
  120.      -----------------------------------------------------}
  121.  
  122.     FUNCTION HasSoftPower: BOOLEAN;
  123.  
  124.         CONST
  125.             kGestaltTrapNum = $AD; { Trap Number of Gestalt }
  126.             kUnImplTrapNum = $9F; { Trap Number of Unimplemented Trap }
  127.  
  128.         VAR
  129.             GestaltIsImplemented: BOOLEAN; { True if Gestalt is implemented }
  130.             gestaltErr: OSErr; { Error returned from Gestalt }
  131.             theHardwareAttr: LONGINT; { attributes holder }
  132.             temp : BOOLEAN;
  133.  
  134.         BEGIN
  135.             temp := FALSE;            
  136.  
  137.             { Is Gestalt available? }
  138.             GestaltIsImplemented := NGetTrapAddress(kGestaltTrapNum, OSTrap) <>
  139.                                     NGetTrapAddress(kUnImplTrapNum, ToolTrap);
  140.                                     
  141.             IF GestaltIsImplemented THEN BEGIN
  142.                 gestaltErr := Gestalt(gestaltHardwareAttr, theHardwareAttr);
  143.                 IF gestaltErr = noErr THEN BEGIN
  144.                     { use MPW's BTst function }
  145.                     IF ( BTst(theHardwareAttr,gestaltHasSoftPowerOff) ) THEN
  146.                         temp := TRUE;
  147.                 END;
  148.             END;
  149.             
  150.             If temp THEN
  151.                 Writeln('Checking for soft power capability.  Result: has soft power capability.')
  152.             ELSE
  153.                 Writeln('Checking for soft power capability.  Result:  no soft power capability.');
  154.             PLFlush(Output);
  155.             
  156.             HasSoftPower := temp;
  157.         END;
  158.  
  159.     {-----------------------------------------------------
  160.       SetEgretWakeUpTime - assembly language stub to call
  161.       the Egret trap to set a wakeup time
  162.      -----------------------------------------------------}
  163.  
  164.     PROCEDURE SetEgretWakeUpTime(WakeUpWhen: LONGINT);
  165.         EXTERNAL;
  166.  
  167.  
  168.     {-----------------------------------------------------
  169.       ShowTime - show a prompt string and convert a 
  170.       DateTimeRec into hour, minute, seconds
  171.      -----------------------------------------------------}
  172.  
  173.     PROCEDURE ShowTime(thePromptStr: str255; theSeconds: LONGINT);
  174.  
  175.         VAR
  176.             myDateTimeRec: DateTimeRec;
  177.  
  178.         BEGIN
  179.             Secs2Date(theSeconds, myDateTimeRec);
  180.             write(thePromptStr);
  181.             WITH myDateTimeRec DO BEGIN
  182.                 write(hour: 2, ':');
  183.                 write(minute: 2, ':');
  184.                 writeln(second: 2);
  185.             END;
  186.             PLFlush(Output);
  187.         END; {procedure}
  188.  
  189.  
  190.     {-----------------------------------------------------
  191.       QuitProgram
  192.      -----------------------------------------------------}
  193.  
  194.     PROCEDURE QuitProgram;
  195.  
  196.         BEGIN
  197.             writeln;
  198.             writeln('goodbye');
  199.             PLFlush(Output);
  200.         END; {procedure}
  201.  
  202.  
  203.  
  204.         {=====================================================
  205.           Main program
  206.          =====================================================}
  207.  
  208.     BEGIN
  209.         writeln('Program Version number: ', kProgramVersion);
  210.         writeln;
  211.         PLFlush(Output); {SIOW apps need PLFlush after writes to show I/O right away}
  212.  
  213.         IF HasEgretHW THEN BEGIN {has egret hardware}
  214.         {let's see if it has soft power capability as well - we need both}
  215.             IF HasSoftPower THEN BEGIN {has SoftPower}
  216.                 gErr := ReadDateTime(gPresentTime); {time in ticks}
  217.                 IF gErr = noErr THEN BEGIN
  218.                     writeln;
  219.                     ShowTime('The present time is:', gPresentTime);
  220.                     gPresentTime := gPresentTime + (kMinutesToDelay * 60);
  221.                     ShowTime('I will wake up at:', gPresentTime);
  222.                     
  223.                     {debugStr('ready to call SetEgretWakeUpTime');}
  224.                     
  225.                     IF HasEgretTrap THEN
  226.                         SetEgretWakeUpTime(gPresentTime); {this assembly stub calls Egret trap}
  227.                 END {has SoftPower}
  228.             END
  229.             ELSE BEGIN {No soft power}
  230.                 writeln('No soft power - unable to set a wakeup time.');
  231.                 PLFlush(Output);
  232.             END {No soft power}
  233.         END {has egret hardware}
  234.         ELSE BEGIN {no egret}
  235.             writeln('No egret - unable to set a wakeup time.');
  236.             PLFlush(Output);
  237.         END; {no egret}
  238.  
  239.         QuitProgram;
  240.     END.
  241.